import Vue from 'vue'
import VueRouter from 'vue-router'

const Login = () => import('../components/Login')
const Home = () => import('../components/Home')
const Welcome = () => import('../components/Welcome')
const Category = () => import('../components/goods/Category')
const Real = () => import('../components/statistics/Real')
const Cnzz = () => import('../components/statistics/Cnzz')
const Cost = () => import('../components/statistics/Cost')
const Site = () => import('../components/statistics/Site')
const Goods = () => import('../components/goods/Goods')
const GoodsAdd = () => import('../components/goods/goodsChildComponents/GoodsAdd')
/* const Users = () => import('../components/user/Users')
const Rights = () => import('../components/rights/Rights')
const Roles = () => import('../components/rights/Roles')
const Category = () => import('../components/goods/Category')
const Params = () => import('../components/goods/Params')
const GoodsList = () => import('../components/goods/List')
const GoodsAdd = () => import('../components/goods/listChildComponents/ListAdd')
const Report = () => import('../components/report/Report') */
const Order = () => import('../components/order/Order')
const OrderSetting = () => import('../components/order/Setting')
const OrderDetail = () => import('../components/order/orderChildComponents/OrderDetail')
const OrderDelivery = () => import('../components/order/orderChildComponents/OrderDelivery')
const Trade = () => import('../components/order/Trade')
const User = () => import('../components/user/User')
const Shop = () => import('../components/goods/Shop')
const Attribute = () => import('../components/goods/Attribute')
const Term = () => import('../components/goods/Term')
const Sign = () => import('../components/task/Sign')
const Task = () => import('../components/task/Task')
const Lottery = () => import('../components/task/Lottery')
const Red = () => import('../components/task/Red')
const Hunt = () => import('../components/task/Hunt')
const Share = () => import('../components/task/Share')
const Customer = () => import('../components/customer/Customer')
const Knowledge = () => import('../components/customer/Knowledge')
const Refund = () => import('../components/order/Refund')
const RefundList = () => import('../components/order/refundChildComponents/RefundList')
const RefundDetail = () => import('../components/order/refundChildComponents/RefundDetail')
const Notify = () => import('../components/system/Notify')
const Config = () => import('../components/system/Config')
const Supplier = () => import('../components/supply/Supplier')
const Sync = () => import('../components/supply/Sync')
const Brand = () => import('../components/supply/Brand')
const SupplyCategory = () => import('../components/supply/Category')
const FailedDetail = () => import('../components/supply/syncChildComponents/FailedDetail')
const WithdrawSetting = () => import('../components/withdraw/Setting')
const WithdrawList = () => import('../components/withdraw/List')
const WithdrawDetail = () => import('../components/withdraw/Detail')
const Price = () => import('../components/goods/Price')
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/home',
    component: Home,
    redirect: '/welcome',
    children: [
      {
        path: '/welcome',
        component: Welcome
      },
      {
        path: '/categories',
        component: Category
      },
      {
        path: '/cnzz',
        component: Cnzz
      },
      {
        path: '/cost',
        component: Cost
      },
      {
        path: '/site',
        component: Site
      },
      {
        path: '/goods',
        component: Goods
      },
      {
        path: '/shop',
        component: Shop
      },
      {
        path: '/price',
        component: Price
      },
      {
        path: '/term',
        component: Term
      },
      {
        path: '/attribute',
        component: Attribute
      },
      {
        path: '/add',
        component: GoodsAdd
      },
      {
        path: '/trades',
        component: Trade
      },
      {
        path: '/refund',
        component: Refund
      },
      {
        path: '/refunds',
        component: RefundList
      },
      {
        path: '/refundDetail',
        component: RefundDetail
      },
      {
        path: '/orders',
        component: Order
      },
      {
        path: '/users',
        component: User
      },
      {
        path: '/detail',
        component: OrderDetail
      },
      {
        path: '/delivery',
        component: OrderDelivery
      },
      {
        path: '/real',
        component: Real
      },
      {
        path: '/sign',
        component: Sign
      },
      {
        path: '/task',
        component: Task
      },
      {
        path: '/lottery',
        component: Lottery
      },
      {
        path: '/red',
        component: Red
      },
      {
        path: '/hunt',
        component: Hunt
      },
      {
        path: '/share',
        component: Share
      },
      {
        path: '/customer',
        component: Customer
      },
      {
        path: '/knowledge',
        component: Knowledge
      },
      {
        path: '/orderSetting',
        component: OrderSetting
      },
      {
        path: '/supplier',
        component: Supplier
      },
      {
        path: '/sync',
        component: Sync
      },
      {
        path: '/brand',
        component: Brand
      },
      {
        path: '/supply-category',
        component: SupplyCategory
      },
      {
        path: '/failed',
        component: FailedDetail
      },
      {
        path: '/notify',
        component: Notify
      },
      {
        path: '/config',
        component: Config
      },
      {
        path: '/withdrawSetting',
        component: WithdrawSetting
      },
      {
        path: '/withdrawList',
        component: WithdrawList
      },
      {
        path: '/withdrawDetail',
        component: WithdrawDetail
      }
      /* {
        path: '/categories',
        component: Category
      },
      {
        path: '/params',
        component: Params
      },
      {
        path: '/goods',
        component: GoodsList
      },
      {
        path: '/add',
        component: GoodsAdd
      },
      {
        path: '/reports',
        component: Report
      } */
    ]
  }
]

const router = new VueRouter({
  routes
})

// 添加全局前置导航守卫
router.beforeEach((to, from, next) => {
  // 如果访问的是登录页，直接放行
  if (to.path === '/login') return next()
  // 从sessionStorage中取出token值
  const token = sessionStorage.getItem('token')
  // 如果token不存在，说明没有登录，就强制跳转到登录页
  if (!token) {
    return next('/login')
  }
  next()
})

export default router
